import React, { Component } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { Link } from 'react-router'
import { Table, Spin, Form, Row, Col, Input, Button, Tree, Select, Modal, Dropdown, Menu, Popconfirm, Icon, message, Checkbox, TreeSelect } from 'antd'

import Ajax from 'lib/Ajax'
import { getNameByCode, confirmDelete, findRowData } from 'lib/fun'
const FormItem = Form.Item;
const Option = Select.Option;
const SelectTreeNode = TreeSelect.TreeNode;

class ModuleName extends Component {
  constructor(props) {
    super(props);
    this.state = {
      loading: false,
      registerList: []
    }

    this.identNumber = "";
  }

  componentDidMount(){

  }

  handleFilter = ()=>{
    var self = this;
    this.props.form.validateFields((err, values) => {
      if(values.identNumber&&values!=this.identNumber){
        this.identNumber = values.identNumber;
        self.loadData();
      }
    });
  }

  loadData = ()=>{
    var self = this;
    self.setState({
      loading: true
    });
    Ajax({
      url: '/mobile/citizen/getRegisterList',
      data: {
        identNumber: this.identNumber
      },
      success: function(data){
        self.setState({
          registerList: data,
          loading: false
        });
      },
      error: function(error){
        message.error(error);
        self.setState({
          loading: false
        });
      }
    });
  }

  render() {
    const columns = [{
        title: '用户行政区划',
        dataIndex: 'areaName'
      }, {
        title: '姓名',
        dataIndex: 'name'
      }, {
        title: '身份证号码',
        dataIndex: 'identNumber'
      }, {
        title: '补贴年度',
        dataIndex: 'year'
      }, {
        title: '补贴项目',
        dataIndex: 'projectName'
      }, {
        title: '发放周期',
        dataIndex: 'payCycleName'
       }, {
        title: '发放次数',
        dataIndex: 'subsidyCount'
      }, {
        title: '发放银行',
        dataIndex: 'bankName'
      }, {
        title: '银行卡号',
        dataIndex: 'bankNumber'
      }, {
        title: '发放金额',
        dataIndex: 'subsidyMoney'
      }, {
        title: '发放状态',
        dataIndex: 'stateName'
      }];

    const { getFieldDecorator } = this.props.form;
    const formItemLayout = {
      labelCol: { span: 10 },
      wrapperCol: { span: 14 },
    };

    return (
      <div className="area" style={{paddingTop:10}}>
        <Row gutter={10}>
          <Col span={9}>
            <FormItem {...formItemLayout} label="请输入查询的身份证号码">
              {getFieldDecorator("identNumber", {
                rules: [{
                  required: true, message: '请输入身份证号码',
                }]
              })(
                <Input size="default" />
              )}
            </FormItem>
          </Col>
          <Col span={5}>
            <Button type="primary" onClick={this.handleFilter} style={{top: 2}}>查询</Button>
          </Col>
        </Row>
        <div className="area-con" style={{marginTop:0}}>
          <Table
            columns={ columns }
            dataSource={ this.state.registerList }
            loading={this.state.loading}
            rowKey="registerId"
            pagination={false}
          />
        </div>
      </div>
    )
  }
}


module.exports = Form.create()(ModuleName)